package common.service.base.common;

import com.alibaba.fastjson.JSON;

/**
 * @ClassName ResponseData
 * @Description Todo
 * @Author yanghao
 * @Date 2018/8/15 下午3:37 Version 0.0.1
 **/
public class ResponseData {

    private String status;
    private String msg;
    private Object data;

    public ResponseData(String status, String msg, Object data) {
        this.status = status;
        this.msg = msg;
        this.data = data;
    }

    ResponseData(String status, String msg) {
        this.status = status;
        this.msg = msg;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public static String success() {
        return success(null);
    }

    public static String success(Object data) {
        return success(Constant.MSG_SUCCESS, data);
    }

    public static String success(String msg, Object data) {
        return toString(Constant.STATUS_SUCCESS, msg, data);
    }

    public static String fail() {
        return fail(null);
    }

    public static String fail(Object data) {
        return fail(Constant.MSG_FAIL, data);
    }

    public static String fail(String msg, Object data) {
        return toString(Constant.STATUS_FAIL, msg, data);
    }

    private static String toString(String code, String msg, Object data) {
        return JSON.toJSONString(new ResponseData(code, msg, data));
    }

}
